package com.xi.service.Impl;

import com.xi.mapper.ManagerMapper;
import com.xi.pojo.Log;
import com.xi.pojo.Manager;
import com.xi.service.ManagerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;

@Service
public class ManagerServiceImpl implements ManagerService {
    @Autowired
    private ManagerMapper managerMapper;

    @Autowired
    private LogServiceImpl logService;

    /*
     * 管理员登录
     * */
    @Override
    public Log login(Manager manager) {
        // 获取数据库中的用户名密码
        Manager managerLogin = managerMapper.getUsernameAndPassword(manager);

        //获取登录日志进行返回
        Log log = new Log();

        //设置为管理员登录
        log.setRole(1);
        log.setOperatingTime(LocalDateTime.now());
        log.setStatus(managerLogin != null ? 1 : 0);

        //进行登录日志信息添加
        logService.addLog(log);
        return log;
    }
}
